package hfdp.chp07.chp0701.impl;


import hfdp.chp07.chp0701.service.Duck;
import hfdp.chp07.chp0701.service.Turkey;

/**
 * 
 * @author cyw
 *
 */
/*
 * First, you need to implement the interface of the type you’re adapting to.
 * This is the interface your client expects to see.
 */
public class TurkeyAdapter implements Duck {

	private Turkey turkey;
	/**
	 * Next, we need to get a reference to the object that we are adapting; here we do that through the constructor
	 * @param turkey
	 */
	public TurkeyAdapter(Turkey turkey) {
		this.turkey = turkey;
	}
	
	/**
	 * Now we need to implement all the methods in the interface; the quack() translation between classes is easy: 
	 * just call the gobble() method.
	 */
	@Override
	public void quack() {
		turkey.gobble();
	}
	
	/**
	 * Even though both interfaces have a fly() method, Turkeys fly in short spurts - they can’t do long-distance flying like ducks. 
	 * To map between a Duck’s fly() method and a Turkey’s, we need to call the Turkey’s fly() method five times to make up for it.
	 */
	@Override
	public void fly() {
		for (int i = 0; i < 5; i++) {
			turkey.fly();
		}
	}

}
